﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace NCC_SOP
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                initBind();
            }
        }

        private void insertListItems(DropDownList lst, string itemName)
        {
            string connectionString = "server=localhost;database=ncc-sop;uid=sa;password=lifebook;";
            using (SqlConnection SqlConnection = new SqlConnection(connectionString))
            {
                string selectSQL = "select TableAttributeValue " +
                                   "from MetadataTableAttributeValues inner join MetadataTableAttributes " +
                                   "on MetadataTableAttributeValues.TableAttributeId = MetadataTableAttributes.TableAttributeId " +
                                   "where TableAttributeName = '" + itemName + "' ";
                SqlCommand cmd = new SqlCommand(selectSQL, SqlConnection);
                SqlConnection.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    ListItem newItem = new ListItem();
                    newItem.Text = reader["TableAttributeValue"].ToString();
                    newItem.Value = reader["TableAttributeValue"].ToString();
                    lst.Items.Add(newItem);
                }
                reader.Close();
            }
        }

        protected void initBind()
        {
            insertListItems(this.datasource_dl, "dataSource");
            insertListItems(this.rptType_dl, "dataType");
            insertListItems(this.tagger_dl, "data_filter1");
        }
        
        
        protected void DataSourceList_SelectedIndexChanged(object sender, EventArgs e)
        {
            /*
            switch(DataSourceList.SelectedValue) 
            {
                case "1":
                    ReportList.DataSource = ReportSource1;
                    break;
                case "2":
                    ReportList.DataSource = ReportSource2;
                    break;
                case "3":
                    ReportList.DataSource = ReportSource3;
                    break;
            }
            ReportList.DataBind();
            ReportList.Items.Insert(0, "0");
             * */
        }

        protected void ReportList_SelectedIndexChanged(object sender, EventArgs e)
        {
            /*
            switch(ReportList.SelectedValue) {
                case "4":
                    TaggerList.DataSource = TaggerSource4;
                    break;
                case "5":
                    TaggerList.DataSource = TaggerSource5;
                    break;
                case "6":
                    TaggerList.DataSource = TaggerSource6;
                    break;
                case "7":
                    TaggerList.DataSource = TaggerSource7;
                    break;
                case "8":
                    TaggerList.DataSource = TaggerSource8;
                    break;
                case "9":
                    TaggerList.DataSource = TaggerSource9;
                    break;
            }
            TaggerList.DataBind();
            TaggerList.Items.Insert(0, "0");
             * */
        }

        protected void TaggerList_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            /*
            Display.Text = DataSourceList.SelectedValue + " " + ReportList.SelectedValue + " " + TaggerList.SelectedValue;
             * */
        }
    }
}